package com.aaa.ssm.service.impl;

import com.aaa.ssm.entity.Student;
import com.aaa.ssm.entity.StudentQuery;
import com.aaa.ssm.entity.StudentVO;
import com.aaa.ssm.mapper.StudentMapper;
import com.aaa.ssm.service.StudentService;
import com.aaa.ssm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author AUSU
 * @version 1.0
 * 创建时间：2025/3/22 16:04
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public AjaxResult queryStudent(StudentQuery query) {
        List<Student> students = studentMapper.queryStudentByQuery(query);
        Long totalCount = studentMapper.queryStudentTotalCount(query);

        HashMap<Object, Object> map = new HashMap<>();
        map.put("currentData",students);
        map.put("totalCount",totalCount);

        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult deleteStudent(Integer id) {
        int i = studentMapper.deleteStudentById(id);
        if (i>0){
            return AjaxResult.success();
        }

        return AjaxResult.error();
    }

    @Override
    public AjaxResult addStudent(StudentVO s) {

        int i = studentMapper.addStudent(s);
        if (i>0){
            return AjaxResult.success();
        }

        return AjaxResult.error();
    }

    @Override
    public AjaxResult getStudentById(Integer id) {

        StudentVO student = studentMapper.getStudent(id);
        return AjaxResult.success(student);

    }

    @Override
    public AjaxResult updateStudentById(StudentVO s) {

        int i = studentMapper.updateStudent(s);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}
